#ifndef GEOMETRY_H_
#define GEOMETRY_H_

#include <e32math.h>
#include <e32base.h> 
#include <gdi.h>
#include <w32adll.h>

// ��窠 � ��嬥୮� ����࠭�⢥
class T3DPoint
{
   public:
      T3DPoint(): iX( 0 ), iY( 0 ), iZ( 0 ) {}	   
      T3DPoint( TInt aX, TInt aY, TInt aZ  ): iX( aX ), iY( aY ), iZ( aZ ) {}
       
      T3DPoint( const T3DPoint& aItem );
      T3DPoint& operator = ( const T3DPoint& aPoint );

   public:		
      TInt iX, iY, iZ;       
};

// ����� TDouble3DPoint �ᯮ������ ��� ���� ����� ���न��� ���設
// ��ࠫ����������, �� �⮬ ⥪�饥 ���祭�� iCurrent �������� �� �᭮�� 
// ��砫쭮�� iOriginal
class TDouble3DPoint
{
   public: 
      TDouble3DPoint( TInt aX, TInt aY, TInt aZ  );	   
      TDouble3DPoint( const TDouble3DPoint& aItem );	  
      TDouble3DPoint& operator = ( const TDouble3DPoint& aPoint );
	   	   	   
   public:
      T3DPoint iOriginal, iCurrent;	
};

// ����� ������ � ��嬥୮� ����࠭�⢥
// �. http://ru.wikipedia.org/wiki/%D0%9C%D0%B0%D1%82%D1%80%D0%B8%D1%86%D0%B0_%D0%BF%D0%BE%D0%B2%D0%BE%D1%80%D0%BE%D1%82%D0%B0
class CTransformMatrix : public CBase
{
   public:
      ~CTransformMatrix();
      static CTransformMatrix* NewL();
	 
      void Refine( TReal anAngleXoffs, TReal anAngleYoffs, TReal anAngleZoffs );	 
      void Reset();
      void Multiply( T3DPoint& aMultiplier, T3DPoint& aResult );
	 
   private:
      CTransformMatrix() {}	  
      void ConstructL();

      CArrayFixFlat<TReal>* InitLineL();
	   
   private:
      CArrayFixFlat<TReal> *iLine1, *iLine2, *iLine3;	
      TReal angleX, angleY, angleZ;
};

//  ������� � ������� ���ண� ���ᮢ뢠���� �࠭� ��ࠫ����������
class TParallelepipedPoly 
{
   public:
      TParallelepipedPoly(TRgb aColor): iColor( aColor ), iVisible( ETrue ) {}
      TParallelepipedPoly( const TParallelepipedPoly& aPoly );
	   
      TParallelepipedPoly& operator = ( const TParallelepipedPoly& aPoly );
    	    	
      void SetArray( TPoint* anArray );       
      void SetPoint( TInt aPointIdx, TInt aX, TInt aY );
       
    public:     	
      TPoint iPoint1, iPoint2, iPoint3, iPoint4;
      TRgb  iColor;	   
      TBool iVisible;
};


class CFbsBitmapDevice;
class CFbsBitGc;

// ����� �����뢠�� ���न���� ���設 ��ࠫ����������, ���ᮢ뢠�� ��� �
// ��������� ���饭�� 㣫�� ������
class CParallelepiped : public CBase
{
   public:
      CParallelepiped( TReal aMultiplier, TDisplayMode aMode ); 
      void ConstructL();
     ~CParallelepiped();

      void SetPolyPoint( TInt aPolyNo, TInt aPointNo, TInt aValueX, TInt aValueY );
      void SetInitPoints( const TRect& aRect, const TPoint& aPoint ); 
      void SetFocused( TInt aFocus );
      void SetGauge( TInt aGauge ); 
      void SetCurrentGaugeValue( TInt aValue );

      void Calc();
      void Reset();
      void SizeChanged( const TRect& aRect, const TPoint& aPoint ); 

      void Draw( CAnimGc& aGc ) const;
      void DrawGauge( CFbsBitGc& aGc, TBool aActive, TInt aValue, TInt aYOffset ) const;
            
      TBool Focused() const;
            
   private:
      CArrayFixFlat<TDouble3DPoint> *iPoints;      // ���設� ��ࠫ����������
      CArrayFixFlat<TParallelepipedPoly> *iPolies; // �������� ��� �⮡ࠦ���� �࠭��
      CTransformMatrix* iMatrix;                   // ����� ������

      TPoint* iPoly;                               // �ᯮ����⥫�� ���ᨢ ��� ���ᮢ�� �࠭�
      TPoint* iGaugePoly;                          // �ᯮ����⥫�� ���ᨢ ��� ���ᮢ�� ��������
	   
   private:
      TPoint iPoint;          // ᬥ饭�� ������ ���孥�� 㣫� iOffScreenBitmap
      TRect  iRect;           // �������, �ᯮ��㥬�� ��� ���ᮢ��
      TInt   iDx, iDy, iDz;   // ⥪�騥 ���祭�� ���饭�� 㣫�� ������
      TInt*  iDCurrent;       // ⥪�騩 ��������
      TReal  iMultiplier;

      TBool  iFocused;

      // ����ࠦ���� ��ࢮ��砫쭮 ���ᮢ뢠���� �� iOffScreenBitmap
      TDisplayMode iMode;
      CFbsBitmap* iOffScreenBitmap;
      CFbsBitmapDevice* iOffScreenBitmapDevice;
      CFbsBitGc* iOffScreenBitmapGc;      	   
};


#endif /*GEOMETRY_H_*/
